package com.example.points.controller;

import com.example.points.domain.UserPoints;
import com.example.points.domain.PointsOperationLog;
import com.example.points.dto.BatchPointsRequest;
import com.example.points.service.PointsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/points")
@RequiredArgsConstructor
public class PointsController {
    private final PointsService pointsService;

    @GetMapping("/{userId}")
    public UserPoints queryUserPoints(@PathVariable Long userId) {
        return pointsService.queryUserPoints(userId);
    }

    @PostMapping("/recharge/{userId}")
    public void rechargePoints(@PathVariable Long userId, @RequestParam Long points) {
        pointsService.rechargePoints(userId, points);
    }

    @PostMapping("/consume/{userId}")
    public boolean consumePoints(@PathVariable Long userId, @RequestParam Long points) {
        return pointsService.consumePoints(userId, points);
    }

    @PostMapping("/batch/recharge")
    public void batchRechargePoints(@RequestBody BatchPointsRequest request) {
        pointsService.batchRechargePoints(request.getUserIds(), request.getPoints());
    }

    @PostMapping("/batch/consume")
    public void batchConsumePoints(@RequestBody BatchPointsRequest request) {
        pointsService.batchConsumePoints(request.getUserIds(), request.getPoints());
    }

    @GetMapping("/logs")
    public List<PointsOperationLog> queryOperationLogs(
            @RequestParam(required = false) Long userId,
            @RequestParam(required = false) Integer operationType,
            @RequestParam String startTime,
            @RequestParam String endTime) {
        return pointsService.queryOperationLogs(userId, operationType, startTime, endTime);
    }
} 